package com.huahang.fashionpress.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huahang.fashionpress.form.FormImg;
import com.huahang.fashionpress.model.Img;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: 阿俊哥 李梦阳
 * @Date: 2019/8/20 15:35
 * @Version 1.0
 *
 * 更新
 * @author : 王翰聪
 * @since : 2019/08/24
 * @version : 1.1
 * 添加了查询商品详细图片的方法
 */
@Repository
public interface ImgMapper extends BaseMapper<Img> {

    @Select("select img_name from t_img where product_id=#{productId} and img_status=#{status}")
    List<Img> getSingleProductImgList(String productId, Integer status);
    /*
    * */
    @Select("SELECT i.*, x.product_name\n" +
            "FROM t_img i\n" +
            "LEFT JOIN t_product x ON i.product_id = x.product_id")
    List<FormImg> SelectAllImgs();

    //
    @Select("SELECT i.*,x.product_name\n" +
            "FROM t_img i\n" +
            "LEFT JOIN t_product x ON i.product_id = x.product_id\n" +
            "WHERE i.img_id =#{id}")
    FormImg SelectFImgByimg_id(int id);

    //
    @Select("SELECT i.*,x.product_name\n" +
            "FROM t_img i\n" +
            "LEFT JOIN t_product x ON i.product_id = x.product_id\n" +
            "WHERE i.product_id =#{id}")
    List<FormImg> SelectFImgByproduct_id(String id);

    //
    @Select("select * from t_img where img_id=#{id}")
    Img SelectImgByimg_id(int id);

    //
    @Select("select distinct product_id from t_img")
    List<String> SelectAllproductId();

    //
    @Select("select * from t_img where product_id=#{id}")
    List<Img> SelectImgByproduct_id(String id);

    //
    @Select("select * from t_img where product_id=#{id}and img_status=1")
    Img SelectPrImgByproduct_id(String id);

    //
    @Delete("delete from t_img where product_id=#{id}")
    void deleteimgsByproduct_id(String id);

    //
    @Delete("delete from t_img where img_id = #{id}")
    void deleteImgByimg_id(int id);
}
